﻿using log4net.Config;
using System;
using System.IO;
using Topshelf;

namespace NiuBeService
{
    class Program
    {
        static void Main(string[] args)
        {
            //1.安装方式:  cd 到本程序目录  。 执行 本程序名.exe install 即可安装成功。net start 服务名可以启动
            //你也可以使用windows服务找到后点击启动

            //2.生成成功后,会有Install.bat 和 Unstall.bat 您可以双击Install.bat进行安装与启动

            XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"));

            var setting = JsonConfig.Get<ServiceInfo>("ServiceInfo.json").Detail;

            HostFactory.Run(x =>
            {
                x.Service<ProgramRunner>(s =>
                {
                    s.ConstructUsing(name => new ProgramRunner());
                    s.WhenStarted(async tc => await tc.StartAsync());
                    s.WhenStopped(async tc => await tc.StopAsync());
                });
                x.RunAsLocalSystem();
                x.StartAutomatically();
                x.SetDescription(setting.ServiceDescription);
                x.SetDisplayName(setting.ServiceDisplayName);
                x.SetServiceName(setting.ServiceName);
            });
            Console.ReadKey();
        }
    }
}


